package com.kele.test.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig_Topic {

    private static final String QUEUE_NAME_1 = "topic_Q1";
    private static final String QUEUE_NAME_2 = "topic_Q2";
    private static final String QUEUE_NAME_3 = "topic_Q3";
    private static final String EXCHANGE_NAME = "exchange_topic";

    @Bean(QUEUE_NAME_1)
    public Queue queueDeclare_topic1(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_1).build();
    }
    @Bean(QUEUE_NAME_2)
    public Queue queueDeclare_topic2(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_2).build();
    }
    @Bean(QUEUE_NAME_3)
    public Queue queueDeclare_topic3(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_3).build();
    }

    @Bean(EXCHANGE_NAME)
    public Exchange exchangeDeclare_topic(){
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Binding bindingDeclare_topic1(
            @Qualifier(QUEUE_NAME_1) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.email.#").noargs();
    }

    @Bean
    public Binding bindingDeclare_topic2(
            @Qualifier(QUEUE_NAME_2) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.sms.#").noargs();
    }

    @Bean
    public Binding bindingDeclare_topic3(
            @Qualifier(QUEUE_NAME_3) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#").noargs();
    }
}
